package com.cssw.fyzb.web.config;

import com.cssw.fyzb.core.es.EsClient;
import com.cssw.fyzb.core.mongo.MongoClient;
import com.cssw.fyzb.core.mongo.MongoOptions;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author YangYiQun
 */
@Configuration
public class MongoConfig {

    @Value("${mongo.seeds}")
    private String seeds;

    @Value("${mongo.db}")
    private String db;

    @Value("${mongo.user}")
    private String user;

    @Value("${mongo.pwd}")
    private String pwd;

    @Value("${mongo.options.maxWaitTime}")
    private int maxWaitTime;

    @Value("${mongo.options.coTimeout}")
    private int coTimeout;

    @Value("${mongo.options.soTimeout}")
    private int soTimeout;

    @Value("${mongo.options.coPerHost}")
    private int coPerHost;

    @Value("${mongo.options.coMultiplier}")
    private int coMultiplier;


    @Bean(value = "mongoClient")
    public MongoClient create() {
        MongoOptions mongoOptions = new MongoOptions();
        mongoOptions.setMaxWaitTime(maxWaitTime);
        mongoOptions.setCoTimeout(coTimeout);
        mongoOptions.setSoTimeout(soTimeout);
        mongoOptions.setCoPerHost(coPerHost);
        mongoOptions.setCoMultiplier(coMultiplier);
        MongoClient mongoClient = new MongoClient(seeds, db, user, pwd, mongoOptions);
        return mongoClient;
    }
}
